package tv.danmaku.ijk.media.player;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.PowerManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;

import com.bytedance.common.utility.d.SoLibraryLoader;

import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;

import tv.danmaku.ijk.media.player.IjkMediaMeta.IjkStreamMeta;
import tv.danmaku.ijk.media.player.annotations.AccessedByNative;
import tv.danmaku.ijk.media.player.annotations.CalledByNative;
import tv.danmaku.ijk.media.player.misc.IMediaDataSource;
import tv.danmaku.ijk.media.player.misc.IjkTrackInfo;
import tv.danmaku.ijk.media.player.pragma.DebugLog;

public final class IjkMediaPlayer extends AbstractMediaPlayer {
    public static class DefaultMediaCodecSelector implements OnMediaCodecSelectListener {
        public static final DefaultMediaCodecSelector sInstance = new DefaultMediaCodecSelector();

        public DefaultMediaCodecSelector() {

        }

        @TargetApi(value = 16)
        public String onMediaCodecSelect(IMediaPlayer arg16, String arg17, int arg18, int arg19) {
            String v1;
            if (Build.VERSION.SDK_INT < 16) {
                v1 = null;
            } else if (TextUtils.isEmpty(arg17)) {
                v1 = null;
            } else {
                Log.i(IjkMediaPlayer.TAG, String.format(Locale.US, "onSelectCodec: mime=%s, profile=%d, level=%d", arg17, Integer.valueOf(arg18), Integer.valueOf(arg19)));
                ArrayList v3 = new ArrayList();
                int v4 = MediaCodecList.getCodecCount();
                int v2;
                for (v2 = 0; v2 < v4; ++v2) {
                    MediaCodecInfo v5 = MediaCodecList.getCodecInfoAt(v2);
                    Log.d(IjkMediaPlayer.TAG, String.format(Locale.US, "  found codec: %s", v5.getName()));
                    if (!v5.isEncoder()) {
                        String[] v6 = v5.getSupportedTypes();
                        if (v6 != null) {
                            int v7 = v6.length;
                            int v1_1;
                            for (v1_1 = 0; v1_1 < v7; ++v1_1) {
                                String v8 = v6[v1_1];
                                if (!TextUtils.isEmpty(((CharSequence) v8))) {
                                    Log.d(IjkMediaPlayer.TAG, String.format(Locale.US, "    mime: %s", v8));
                                    if (v8.equalsIgnoreCase(arg17)) {
                                        IjkMediaCodecInfo v8_1 = IjkMediaCodecInfo.setupCandidate(v5, arg17);
                                        if (v8_1 != null) {
                                            v3.add(v8_1);
                                            Log.i(IjkMediaPlayer.TAG, String.format(Locale.US, "candidate codec: %s rank=%d", v5.getName(), Integer.valueOf(v8_1.mRank)));
                                            v8_1.dumpProfileLevels(arg17);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (v3.isEmpty()) {
                    return null;
                }

                Object v1_2 = v3.get(0);
                Iterator v3_1 = v3.iterator();
                Object v2_1;
                for (v2_1 = v1_2; v3_1.hasNext(); v2_1 = v1_2) {
                    v1_2 = v3_1.next();
                    if (((IjkMediaCodecInfo) v1_2).mRank <= ((IjkMediaCodecInfo) v2_1).mRank) {
                        v1_2 = v2_1;
                    }
                }

                if (((IjkMediaCodecInfo) v2_1).mRank < 600) {
                    Log.w(IjkMediaPlayer.TAG, String.format(Locale.US, "unaccetable codec: %s", ((IjkMediaCodecInfo) v2_1).mCodecInfo.getName()));
                    return null;
                }

                Log.i(IjkMediaPlayer.TAG, String.format(Locale.US, "selected codec: %s rank=%d", ((IjkMediaCodecInfo) v2_1).mCodecInfo.getName(), Integer.valueOf(((IjkMediaCodecInfo) v2_1).mRank)));
                v1 = ((IjkMediaCodecInfo) v2_1).mCodecInfo.getName();
            }

            return v1;
        }
    }

    class EventHandler extends Handler {
        private final WeakReference mWeakPlayer;

        public EventHandler(IjkMediaPlayer arg2, Looper arg3) {
            super(arg3);
            this.mWeakPlayer = new WeakReference(arg2);
        }

        public void handleMessage(Message arg11) {
            long v6 = 100;
            long v4 = 0;
            Object v0 = this.mWeakPlayer.get();
            if (v0 == null || ((IjkMediaPlayer) v0).mNativeMediaPlayer == v4) {
                DebugLog.w(IjkMediaPlayer.TAG, "IjkMediaPlayer went away with unhandled events");
            } else {
                switch (arg11.what) {
                    case 1: {
                        ((IjkMediaPlayer) v0).notifyOnPrepared();
                        return;
                    }
                    case 2: {
                        ((IjkMediaPlayer) v0).notifyOnCompletion();
                        ((IjkMediaPlayer) v0).stayAwake(false);
                        return;
                    }
                    case 3: {
                        long v2 = ((long) arg11.arg1);
                        if (v2 < v4) {
                            v2 = v4;
                        }

                        long v8 = ((IjkMediaPlayer) v0).getDuration();
                        v2 = v8 > v4 ? v2 * v6 / v8 : v4;
                        if (v2 >= v6) {
                            v2 = v6;
                        }

                        ((IjkMediaPlayer) v0).notifyOnBufferingUpdate(((int) v2));
                        return;
                    }
                    case 4: {
                        ((IjkMediaPlayer) v0).notifyOnSeekComplete();
                        return;
                    }
                    case 5: {
                        ((IjkMediaPlayer) v0).mVideoWidth = arg11.arg1;
                        ((IjkMediaPlayer) v0).mVideoHeight = arg11.arg2;
                        ((IjkMediaPlayer) v0).notifyOnVideoSizeChanged(((IjkMediaPlayer) v0).mVideoWidth, ((IjkMediaPlayer) v0).mVideoHeight, ((IjkMediaPlayer) v0).mVideoSarNum, ((IjkMediaPlayer) v0).mVideoSarDen);
                        return;
                    }
                    case 0:
                    case 99: {
                        return;
                    }
                    case 100: {
                        DebugLog.e(IjkMediaPlayer.TAG, "Error (" + arg11.arg1 + "," + arg11.arg2 + ")");
                        if (!((IjkMediaPlayer) v0).notifyOnError(arg11.arg1, arg11.arg2)) {
                            ((IjkMediaPlayer) v0).notifyOnCompletion();
                        }

                        ((IjkMediaPlayer) v0).stayAwake(false);
                        return;
                    }
                    case 200: {
                        switch (arg11.arg1) {
                            case 3: {
                                DebugLog.i(IjkMediaPlayer.TAG, "Info: MEDIA_INFO_VIDEO_RENDERING_START\n");
                                break;
                            }
                        }
                        ((IjkMediaPlayer) v0).notifyOnInfo(arg11.arg1, arg11.arg2);
                        return;
                    }
                    case 10001: {
                        ((IjkMediaPlayer) v0).mVideoSarNum = arg11.arg1;
                        ((IjkMediaPlayer) v0).mVideoSarDen = arg11.arg2;
                        ((IjkMediaPlayer) v0).notifyOnVideoSizeChanged(((IjkMediaPlayer) v0).mVideoWidth, ((IjkMediaPlayer) v0).mVideoHeight, ((IjkMediaPlayer) v0).mVideoSarNum, ((IjkMediaPlayer) v0).mVideoSarDen);
                        return;
                    }
                }

                DebugLog.e(IjkMediaPlayer.TAG, "Unknown message type " + arg11.what);
                return;


            }
        }
    }

    public interface OnControlMessageListener {
        String onControlResolveSegmentUrl(int arg1);
    }

    public interface OnMediaCodecSelectListener {
        String onMediaCodecSelect(IMediaPlayer arg1, String arg2, int arg3, int arg4);
    }

    public interface OnNativeInvokeListener {
        public static final String ARG_RETRY_COUNTER = "retry_counter";
        public static final String ARG_SEGMENT_INDEX = "segment_index";
        public static final String ARG_URL = "url";
        public static final int ON_CONCAT_RESOLVE_SEGMENT = 65536;
        public static final int ON_HTTP_OPEN = 65538;
        public static final int ON_LIVE_RETRY = 65540;
        public static final int ON_TCP_OPEN = 65537;

        boolean onNativeInvoke(int arg1, Bundle arg2);
    }

    public static final int FFP_PROPV_DECODER_AVCODEC = 1;
    public static final int FFP_PROPV_DECODER_MEDIACODEC = 2;
    public static final int FFP_PROPV_DECODER_UNKNOWN = 0;
    public static final int FFP_PROPV_DECODER_VIDEOTOOLBOX = 3;
    public static final int FFP_PROP_FLOAT_PLAYBACK_RATE = 10003;
    public static final int FFP_PROP_INT64_AUDIO_CACHED_BYTES = 20008;
    public static final int FFP_PROP_INT64_AUDIO_CACHED_DURATION = 20006;
    public static final int FFP_PROP_INT64_AUDIO_CACHED_PACKETS = 20010;
    public static final int FFP_PROP_INT64_AUDIO_DECODER = 20004;
    public static final int FFP_PROP_INT64_SELECTED_AUDIO_STREAM = 20002;
    public static final int FFP_PROP_INT64_SELECTED_VIDEO_STREAM = 20001;
    public static final int FFP_PROP_INT64_TCP_READ_BYTES = 30001;
    public static final int FFP_PROP_INT64_VIDEO_CACHED_BYTES = 20007;
    public static final int FFP_PROP_INT64_VIDEO_CACHED_DURATION = 20005;
    public static final int FFP_PROP_INT64_VIDEO_CACHED_PACKETS = 20009;
    public static final int FFP_PROP_INT64_VIDEO_CLOSE_MUTED = 20202;
    public static final int FFP_PROP_INT64_VIDEO_DECODER = 20003;
    public static final int FFP_PROP_INT64_VIDEO_OPEN_MUTED = 20201;
    public static final int IJK_LOG_DEBUG = 3;
    public static final int IJK_LOG_DEFAULT = 1;
    public static final int IJK_LOG_ERROR = 6;
    public static final int IJK_LOG_FATAL = 7;
    public static final int IJK_LOG_INFO = 4;
    public static final int IJK_LOG_SILENT = 8;
    public static final int IJK_LOG_UNKNOWN = 0;
    public static final int IJK_LOG_VERBOSE = 2;
    public static final int IJK_LOG_WARN = 5;
    private static final int MEDIA_BUFFERING_UPDATE = 3;
    private static final int MEDIA_ERROR = 100;
    private static final int MEDIA_INFO = 200;
    private static final int MEDIA_NOP = 0;
    private static final int MEDIA_PLAYBACK_COMPLETE = 2;
    private static final int MEDIA_PREPARED = 1;
    private static final int MEDIA_SEEK_COMPLETE = 4;
    protected static final int MEDIA_SET_VIDEO_SAR = 10001;
    private static final int MEDIA_SET_VIDEO_SIZE = 5;
    private static final int MEDIA_TIMED_TEXT = 99;
    public static final int OPT_CATEGORY_CODEC = 2;
    public static final int OPT_CATEGORY_FORMAT = 1;
    public static final int OPT_CATEGORY_PLAYER = 4;
    public static final int OPT_CATEGORY_SWS = 3;
    public static final int PROP_FLOAT_VIDEO_DECODE_FRAMES_PER_SECOND = 10001;
    public static final int PROP_FLOAT_VIDEO_OUTPUT_FRAMES_PER_SECOND = 10002;
    public static final int SDL_FCC_RV16 = 909203026;
    public static final int SDL_FCC_RV32 = 842225234;
    public static final int SDL_FCC_YV12 = 842094169;
    private static final String TAG;
    private String mDataSource;
    private EventHandler mEventHandler;
    private static volatile boolean mIsLibLoaded;
    private static volatile boolean mIsNativeInitialized;
    @AccessedByNative
    private int mListenerContext;
    @AccessedByNative
    private long mNativeMediaDataSource;
    @AccessedByNative
    private long mNativeMediaPlayer;
    @AccessedByNative
    private int mNativeSurfaceTexture;
    private OnControlMessageListener mOnControlMessageListener;
    private OnMediaCodecSelectListener mOnMediaCodecSelectListener;
    private OnNativeInvokeListener mOnNativeInvokeListener;
    private boolean mScreenOnWhilePlaying;
    private boolean mStayAwake;
    private SurfaceHolder mSurfaceHolder;
    private int mVideoHeight;
    private int mVideoSarDen;
    private int mVideoSarNum;
    private int mVideoWidth;
    private PowerManager.WakeLock mWakeLock;
    private static final IjkLibLoader sLocalLibLoader;

    static {
        TAG = IjkMediaPlayer.class.getName();
        sLocalLibLoader = new IjkLibLoader() {
            @Override
            public final boolean loadLibrary(Context context, String name) throws UnsatisfiedLinkError, SecurityException {
                return SoLibraryLoader.loadLibrary(context, name);
            }
        };
        mIsLibLoaded = false;
        mIsNativeInitialized = false;
    }

    public IjkMediaPlayer(Context context) {
        this(context, IjkMediaPlayer.sLocalLibLoader);
    }

    public IjkMediaPlayer(Context context, IjkLibLoader ijkLibLoader) {
        this.mWakeLock = null;
        this.initPlayer(context, ijkLibLoader);
    }

    private native String _getAudioCodecInfo();

    private static native String _getColorFormatName(int arg0);

    private native int _getLoopCount();

    private native Bundle _getMediaMeta();

    private native float _getPropertyFloat(int arg1, float arg2);

    private native long _getPropertyLong(int arg1, long arg2);

    private native String _getVideoCodecInfo();

    private native void _pause() throws IllegalStateException;

    public final native void _prepareAsync() throws IllegalStateException;

    private native void _release();

    private native void _reset();

    private native void _setDataSource(String arg1, String[] arg2, String[] arg3) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;

    private native void _setDataSource(IMediaDataSource arg1) throws IllegalArgumentException, SecurityException, IllegalStateException;

    private native void _setDataSourceFd(int arg1) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;

    private native void _setLoopCount(int arg1);

    private native void _setOption(int arg1, String arg2, long arg3);

    private native void _setOption(int arg1, String arg2, String arg3);

    private native void _setPropertyFloat(int arg1, float arg2);

    private native void _setPropertyLong(int arg1, long arg2);

    private native void _setStreamSelected(int arg1, boolean arg2);

    private native void _setVideoSurface(Surface arg1);

    private native void _start() throws IllegalStateException;

    private native void _stop() throws IllegalStateException;

    public final void deselectTrack(int arg2) {
        this._setStreamSelected(arg2, false);
    }

    protected final void finalize() throws Throwable {
        super.finalize();
        this.native_finalize();
    }

    public final long getAudioCachedBytes() {
        return this._getPropertyLong(20008, 0);
    }

    public final long getAudioCachedDuration() {
        return this._getPropertyLong(20006, 0);
    }

    public final long getAudioCachedPackets() {
        return this._getPropertyLong(20010, 0);
    }

    public final native int getAudioSessionId();

    public static String getColorFormatName(int arg1) {
        return IjkMediaPlayer._getColorFormatName(arg1);
    }

    public final native long getCurrentPosition();

    public final String getDataSource() {
        return this.mDataSource;
    }

    public final native long getDuration();

    public final MediaInfo getMediaInfo() {
        String[] v0_1;
        int v5 = 2;
        MediaInfo v1 = new MediaInfo();
        v1.mMediaPlayerName = "ijkplayer";
        String v0 = this._getVideoCodecInfo();
        if (!TextUtils.isEmpty(((CharSequence) v0))) {
            v0_1 = v0.split(",");
            if (v0_1.length >= v5) {
                v1.mVideoDecoder = v0_1[0];
                v1.mVideoDecoderImpl = v0_1[1];
            } else if (v0_1.length > 0) {
                v1.mVideoDecoder = v0_1[0];
                v1.mVideoDecoderImpl = "";
            }
        }

        v0 = this._getAudioCodecInfo();
        if (!TextUtils.isEmpty(((CharSequence) v0))) {
            v0_1 = v0.split(",");
            if (v0_1.length >= v5) {
                v1.mAudioDecoder = v0_1[0];
                v1.mAudioDecoderImpl = v0_1[1];
            } else if (v0_1.length > 0) {
                v1.mAudioDecoder = v0_1[0];
                v1.mAudioDecoderImpl = "";
            }
        }

        try {
            v1.mMeta = IjkMediaMeta.parse(this._getMediaMeta());
        } catch (Throwable v0_2) {
            v0_2.printStackTrace();
        }

        return v1;
    }

    public final Bundle getMediaMeta() {
        return this._getMediaMeta();
    }

    public final int getSelectedTrack(int arg5) {
        int v0;
        long v2 = -1;
        switch (arg5) {
            case 1: {
                v0 = ((int) this._getPropertyLong(20001, v2));
                break;
            }
            case 2: {
                v0 = ((int) this._getPropertyLong(20002, v2));
                break;
            }
            default: {
                v0 = -1;
                break;
            }
        }

        return v0;
    }

    @TargetApi(value = 23)
    public final float getSpeed(float arg3) {
        return this._getPropertyFloat(10003, 0f);
    }

    public final long getTcpReadBytes() {
        return this._getPropertyLong(30001, 0);
    }

    public final IjkTrackInfo[] getTrackInfo() {
        Object[] v0_2 = new Object[0];
        IjkTrackInfo[] v0 = null;
        Bundle v1 = this.getMediaMeta();
        if (v1 != null) {
            IjkMediaMeta v1_1 = IjkMediaMeta.parse(v1);
            if (v1_1 != null && v1_1.mStreams != null) {
                ArrayList v2 = new ArrayList();
                Iterator v1_2 = v1_1.mStreams.iterator();
                while (v1_2.hasNext()) {
                    Object v0_1 = v1_2.next();
                    IjkTrackInfo v3 = new IjkTrackInfo(((IjkStreamMeta) v0_1));
                    if (((IjkStreamMeta) v0_1).mType.equalsIgnoreCase("video")) {
                        v3.setTrackType(1);
                    } else if (((IjkStreamMeta) v0_1).mType.equalsIgnoreCase("audio")) {
                        v3.setTrackType(2);
                    }

                    v2.add(v3);
                }

                v0_2 = v2.toArray(new IjkTrackInfo[v2.size()]);
            }
        }

        return ((IjkTrackInfo[]) v0_2);
    }

    public final long getVideoCachedBytes() {
        return this._getPropertyLong(20007, 0);
    }

    public final long getVideoCachedDuration() {
        return this._getPropertyLong(20005, 0);
    }

    public final long getVideoCachedPackets() {
        return this._getPropertyLong(20009, 0);
    }

    public final float getVideoDecodeFramesPerSecond() {
        return this._getPropertyFloat(10001, 0f);
    }

    public final int getVideoDecoder() {
        return ((int) this._getPropertyLong(20003, 0));
    }

    public final int getVideoHeight() {
        return this.mVideoHeight;
    }

    public final float getVideoOutputFramesPerSecond() {
        return this._getPropertyFloat(10002, 0f);
    }

    public final int getVideoSarDen() {
        return this.mVideoSarDen;
    }

    public final int getVideoSarNum() {
        return this.mVideoSarNum;
    }

    public final int getVideoWidth() {
        return this.mVideoWidth;
    }

    private static synchronized void initNativeOnce() {
        if (!IjkMediaPlayer.mIsNativeInitialized) {
            IjkMediaPlayer.native_init();
            IjkMediaPlayer.mIsNativeInitialized = true;
        }
    }

    private void initPlayer(Context context, IjkLibLoader ijkLibLoader) {
        IjkMediaPlayer.loadLibrariesOnce(context, ijkLibLoader);
        IjkMediaPlayer.initNativeOnce();
        Looper looper = Looper.myLooper();
        if (looper != null) {
            this.mEventHandler = new EventHandler(this, looper);
        } else {
            looper = Looper.getMainLooper();
            this.mEventHandler = looper != null ? new EventHandler(this, looper) : null;
        }
        this.native_setup(new WeakReference(this));
    }

    public static boolean isLibLoaded() {
        return IjkMediaPlayer.mIsLibLoaded;
    }

    public final boolean isLooping() {
        boolean v0 = true;
        if (this._getLoopCount() == 1) {
            v0 = false;
        }

        return v0;
    }

    public final boolean isPlayable() {
        return true;
    }

    public final native boolean isPlaying();

    public static void loadLibrariesOnce(Context arg1) {
        IjkMediaPlayer.loadLibrariesOnce(arg1, IjkMediaPlayer.sLocalLibLoader);
    }

    public static synchronized void loadLibrariesOnce(Context context, IjkLibLoader libLoader) {
        if (!IjkMediaPlayer.mIsLibLoaded) {
            if (libLoader == null) {
                libLoader = IjkMediaPlayer.sLocalLibLoader;
            }

            Log.d("travis", "IjkMediaPlayer:::loadLibrariesOnce()#1");
            if (libLoader.loadLibrary(context, "ijkffmpeg") && libLoader.loadLibrary(context, "ijksdl") && libLoader.loadLibrary(context, "ijkplayer")) {
                IjkMediaPlayer.mIsLibLoaded = true;
                Log.d("travis", "IjkMediaPlayer:::loadLibrariesOnce()#2");
            }
        }

    }

    private native void native_finalize();

    private static native void native_init();

    private native void native_message_loop(Object arg1);

    public static native void native_profileBegin(String arg0);

    public static native void native_profileEnd();

    private static native void native_setIsUploadLog(int arg0);

    public static native void native_setLogLevel(int arg0);

    private static native void native_setNetControl(int arg0);

    private static native void native_setTcpReadTimeOut(int arg0);

    private native void native_setup(Object arg1);

    @CalledByNative
    private static boolean onNativeInvoke(Object arg6, int arg7, Bundle arg8) {
        boolean v0_1;
        DebugLog.ifmt(IjkMediaPlayer.TAG, "onNativeInvoke %d", new Object[]{Integer.valueOf(arg7)});
        if (arg6 != null && ((arg6 instanceof WeakReference))) {
            Object v0 = ((WeakReference) arg6).get();
            if (v0 == null) {
                throw new IllegalStateException("<null weakPlayer>.onNativeInvoke()");
            } else {
                OnNativeInvokeListener v3 = ((IjkMediaPlayer) v0).mOnNativeInvokeListener;
                if (v3 == null || !v3.onNativeInvoke(arg7, arg8)) {
                    switch (arg7) {
                        case 65536: {
                            OnControlMessageListener v0_2 = ((IjkMediaPlayer) v0).mOnControlMessageListener;
                            if (v0_2 == null) {
                                v0_1 = false;
                            } else {
                                int v2 = arg8.getInt("segment_index", -1);
                                if (v2 < 0) {
                                    throw new InvalidParameterException("onNativeInvoke(invalid segment index)");
                                } else {
                                    String v0_3 = v0_2.onControlResolveSegmentUrl(v2);
                                    if (v0_3 == null) {
                                        throw new RuntimeException(new IOException("onNativeInvoke() = <NULL newUrl>"));
                                    } else {
                                        arg8.putString("url", v0_3);
                                        v0_1 = true;
                                    }
                                }
                            }

                            return v0_1;
                        }
                        default: {
                            return false;
                        }
                    }
                } else {
                    v0_1 = true;
                }

                return v0_1;
            }
        }

        throw new IllegalStateException("<null weakThiz>.onNativeInvoke()");
    }

    @CalledByNative
    private static String onSelectCodec(Object arg2, String arg3, int arg4, int arg5) {
        DefaultMediaCodecSelector v1_2;
        String v0_1;
        String v1 = null;
        if (arg2 == null || !(arg2 instanceof WeakReference)) {
            v0_1 = v1;
        } else {
            Object v0 = ((WeakReference) arg2).get();
            if (v0 == null) {
                v0_1 = v1;
            } else {
                OnMediaCodecSelectListener v1_1 = ((IjkMediaPlayer) v0).mOnMediaCodecSelectListener;
                if (v1_1 == null) {
                    v1_1 = DefaultMediaCodecSelector.sInstance;
                }

                v0_1 = ((OnMediaCodecSelectListener) v1_1).onMediaCodecSelect(((IMediaPlayer) v0), arg3, arg4, arg5);
            }
        }

        return v0_1;
    }

    public final void pause() throws IllegalStateException {
        this.stayAwake(false);
        this._pause();
    }

    @CalledByNative
    private static void postEventFromNative(Object arg2, int arg3, int arg4, int arg5, Object arg6) {
        if (arg2 != null) {
            Object v0 = ((WeakReference) arg2).get();
            if (v0 != null) {
                if (arg3 == 200 && arg4 == 2) {
                    ((IjkMediaPlayer) v0).start();
                }

                if (((IjkMediaPlayer) v0).mEventHandler == null) {
                    return;
                }

                ((IjkMediaPlayer) v0).mEventHandler.sendMessage(((IjkMediaPlayer) v0).mEventHandler.obtainMessage(arg3, arg4, arg5, arg6));
            }
        }
    }

    public final void prepareAsync() throws IllegalStateException {
        this._prepareAsync();
    }

    public final void release() {
        this.stayAwake(false);
        this.updateSurfaceScreenOn();
        this.resetListeners();
        this._release();
    }

    public final void reset() {
        this.stayAwake(false);
        this._reset();
        this.mEventHandler.removeCallbacksAndMessages(null);
        this.mVideoWidth = 0;
        this.mVideoHeight = 0;
    }

    public final void resetListeners() {
        super.resetListeners();
        this.mOnMediaCodecSelectListener = null;
    }

    public final native void seekTo(long msec) throws IllegalStateException;

    public final void selectTrack(int arg2) {
        this._setStreamSelected(arg2, true);
    }

    public final void setAudioStreamType(int streamType) {
    }

    private void setDataSource(FileDescriptor arg1, long arg2, long arg4) throws IOException, IllegalArgumentException, IllegalStateException {
        this.setDataSource(arg1);
    }

    @TargetApi(value = 13)
    public final void setDataSource(FileDescriptor fd) throws IOException, IllegalArgumentException, IllegalStateException {
        int v0_3;
        if (Build.VERSION.SDK_INT < 12) {
            try {
                Field v0_2 = fd.getClass().getDeclaredField("descriptor");
                v0_2.setAccessible(true);
                v0_3 = v0_2.getInt(fd);
            } catch (IllegalAccessException v0) {
                throw new RuntimeException(((Throwable) v0));
            } catch (NoSuchFieldException v0_1) {
                throw new RuntimeException(((Throwable) v0_1));
            }

            this._setDataSourceFd(v0_3);
        } else {
            ParcelFileDescriptor v1 = ParcelFileDescriptor.dup(fd);
            try {
                this._setDataSourceFd(v1.getFd());
            } catch (Throwable v0_4) {
                v1.close();
                throw v0_4;
            }

            v1.close();
        }
    }

    public final void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
        this.setDataSource(context, uri, null);
    }

    @TargetApi(value = 14)
    public final void setDataSource(Context context, Uri uri, Map headers) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
        Throwable v0_2;
        AssetFileDescriptor v6 = null;
        String v0 = uri.getScheme();
        if ("file".equals(v0)) {
            this.setDataSource(uri.getPath());
            return;
        }

        if (("content".equals(v0)) && ("settings".equals(uri.getAuthority()))) {
            uri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.getDefaultType(uri));
            if (uri == null) {
                throw new FileNotFoundException("Failed to resolve default ringtone");
            }
        }

        AssetFileDescriptor v0_1 = null;
        try {
            v6 = context.getContentResolver().openAssetFileDescriptor(uri, "r");
            if (v6 != null) {
                if (v6.getDeclaredLength() < 0) {
                    this.setDataSource(v6.getFileDescriptor());
                } else {
                    this.setDataSource(v6.getFileDescriptor(), v6.getStartOffset(), v6.getDeclaredLength());
                }
            }
        } catch (IOException v1_1) {
            Log.d(IjkMediaPlayer.TAG, "Couldn\'t open file on client side, trying server side");
            this.setDataSource(uri.toString(), headers);
            return;
        } catch (SecurityException v1_2) {
            Log.d(IjkMediaPlayer.TAG, "Couldn\'t open file on client side, trying server side");
            this.setDataSource(uri.toString(), headers);
            return;
        } finally {
            if (v6 != null) {
                try {
                    v6.close();
                } catch (Exception e) {

                }
            }
        }
    }

    public final void setDataSource(String path) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
        this.mDataSource = path;
        this._setDataSource(path, null, null);
    }

    public final void setDataSource(String arg6, Map arg7) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
        if (arg7 != null && !arg7.isEmpty()) {
            StringBuilder v2 = new StringBuilder();
            Iterator<Map.Entry<?, String>> v3 = arg7.entrySet().iterator();
            while (v3.hasNext()) {
                Map.Entry<?, String> v0 = v3.next();
                v2.append(((Map.Entry) v0).getKey());
                v2.append(":");
                if (!TextUtils.isEmpty(v0.getValue())) {
                    v2.append(((Map.Entry) v0).getValue());
                }

                v2.append("\r\n");
                this.setOption(1, "headers", v2.toString());
            }
        }

        this.setDataSource(arg6);
    }

    public final void setDataSource(IMediaDataSource mediaDataSource) throws IllegalArgumentException, SecurityException, IllegalStateException {
        this._setDataSource(mediaDataSource);
    }

    public final void setDisplay(SurfaceHolder surfaceHolder) {
        this.mSurfaceHolder = surfaceHolder;
        Surface v0 = surfaceHolder != null ? surfaceHolder.getSurface() : null;
        this._setVideoSurface(v0);
        this.updateSurfaceScreenOn();
    }

    public static void setIPV6First(boolean arg1) {
        int v0 = arg1 ? 1 : 0;
        IjkMediaPlayer.native_setNetControl(v0);
    }

    public static void setIsUploadLog(int arg0) {
        IjkMediaPlayer.native_setIsUploadLog(arg0);
    }

    public final void setKeepInBackground(boolean keepInBackground) {
    }

    public final void setLogEnabled(boolean enable) {
    }

    public static void setLogLevel(int arg0) {
        IjkMediaPlayer.native_setLogLevel(arg0);
    }

    public final void setLooping(boolean looping) {
        int v0 = looping ? 0 : 1;
        this.setOption(4, "loop", ((long) v0));
        this._setLoopCount(v0);
    }

    public final void setOnControlMessageListener(OnControlMessageListener arg1) {
        this.mOnControlMessageListener = arg1;
    }

    public final void setOnMediaCodecSelectListener(OnMediaCodecSelectListener arg1) {
        this.mOnMediaCodecSelectListener = arg1;
    }

    public final void setOnNativeInvokeListener(OnNativeInvokeListener arg1) {
        this.mOnNativeInvokeListener = arg1;
    }

    public final void setOption(int arg1, String arg2, String arg3) {
        this._setOption(arg1, arg2, arg3);
    }

    public final void setOption(int arg2, String arg3, long arg4) {
        this._setOption(arg2, arg3, arg4);
    }

    public final void setPropertyLong(int arg1, long arg2) {
        this._setPropertyLong(arg1, arg2);
    }

    public final void setScreenOnWhilePlaying(boolean screenOn) {
        if (this.mScreenOnWhilePlaying != screenOn) {
            if ((screenOn) && this.mSurfaceHolder == null) {
                DebugLog.w(IjkMediaPlayer.TAG, "setScreenOnWhilePlaying(true) is ineffective without a SurfaceHolder");
            }

            this.mScreenOnWhilePlaying = screenOn;
            this.updateSurfaceScreenOn();
        }
    }

    @TargetApi(value = 23)
    public final void setSpeed(float arg2) {
        this._setPropertyFloat(10003, arg2);
    }

    public final void setSurface(Surface surface) {
        if ((this.mScreenOnWhilePlaying) && surface != null) {
            DebugLog.w(IjkMediaPlayer.TAG, "setScreenOnWhilePlaying(true) is ineffective for Surface");
        }

        this.mSurfaceHolder = null;
        this._setVideoSurface(surface);
        this.updateSurfaceScreenOn();
    }

    public static void setTcpReadTimeOut(int arg0) {
        IjkMediaPlayer.native_setTcpReadTimeOut(arg0);
    }

    public final native void setVolume(float leftVolume, float rightVolume);

    @SuppressLint(value = {"Wakelock"})
    public final void setWakeMode(Context context, int mode) {
        int v2;
        int v0;
        if (this.mWakeLock != null) {
            if (this.mWakeLock.isHeld()) {
                v0 = 1;
                this.mWakeLock.release();
            } else {
                v0 = 0;
            }

            this.mWakeLock = null;
            v2 = v0;
        } else {
            v2 = 0;
        }

        this.mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)).newWakeLock(536870912 | mode, IjkMediaPlayer.class.getName());
        this.mWakeLock.setReferenceCounted(false);
        if (v2 != 0) {
            this.mWakeLock.acquire();
        }
    }

    public final void start() throws IllegalStateException {
        this.stayAwake(true);
        this._start();
    }

    @SuppressLint(value = {"Wakelock"})
    private void stayAwake(boolean arg2) {
        if (this.mWakeLock != null) {
            if ((arg2) && !this.mWakeLock.isHeld()) {
                this.mWakeLock.acquire();
            } else if (arg2) {
            } else if (!this.mWakeLock.isHeld()) {
            } else {
                this.mWakeLock.release();
            }
        }

        this.mStayAwake = arg2;
        this.updateSurfaceScreenOn();
    }

    public final void stop() throws IllegalStateException {
        this.stayAwake(false);
        this._stop();
    }

    private void updateSurfaceScreenOn() {
        if (this.mSurfaceHolder != null) {
            SurfaceHolder v1 = this.mSurfaceHolder;
            boolean v0 = !this.mScreenOnWhilePlaying || !this.mStayAwake ? false : true;
            v1.setKeepScreenOn(v0);
        }
    }
}

